﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
@using LeSoft.Application.Code;
<script src="~/Content/adminDefault/js/default.js"></script>
<script>
    $(function () {
        InitialPage();
        GetTree1();
        GetTree2();
        GetGrid();
    });
    //组织机构
    var _organizeid = "@OperatorProvider.Provider.Current().CompanyId";
    var _PStructId = "";
    var _SourceType = "";
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 165.5);
            }, 200);
            e.stopPropagation();
        });
        //组织机构
        $("#PStructTree").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            height: "250px",
            click: function (item) {
                if (_organizeid != item.id) {
                    _organizeid = item.id;
                    GetTree2();
                    _PStructId = item.id;
                    $('#btn_Search').trigger("click");
                }
            }
        });
        $('#PStructTree').ComboBoxTreeSetValue(_organizeid);
    }

    function GetTree1() {
        var item = {
            url: "../../SystemManage/DataItemDetail/GetTreeListAllJson?parentId=4ce18d21-7f33-4c62-b48d-824b7918054f",
            onnodeclick: function (item) {
                _SourceType = item.text;
                $('#btn_Search').trigger("click");
            }
        };
        //初始化
        $("#itemTree1").treeview(item);
    }
    function GetTree2() {
        var item = {
            url: "../../ResourceManage/RS_PStructs/GetTreeJson?IsSubstep=true&type=5&organizeid=" + _organizeid,
            onnodeclick: function (item) {
                _PStructId = item.id;
                $('#btn_Search').trigger("click");
            }
        };
        //初始化
        $("#itemTree2").treeview(item);
    }

    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var queryJson = $("#queryCondition").GetWebControls();
        queryJson["Organizeid"] = _organizeid;
        queryJson["PStructId"] = _PStructId;
        queryJson["SourceType"] = _SourceType;
        queryJson["State"] = $("#State .dropdown-text").attr('data-value');
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_Rectification/GetPageListJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 165.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", hidden: true },
                { label: "父级主键", name: "SourceId", hidden: true },
                { label: "单据编号", name: "Code", index: "Code", width: 80, align: "left" },
                {
                    label: "单据日期", name: "StateDate", index: "StateDate", width: 80, align: "left", formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd');
                    }
                },
                { label: "来源", name: "SourceType", index: "SourceType", width: 80, align: "left" },
                { label: "来源Id", name: "SourceTypeId", index: "SourceTypeId", width: 80, align: "left" },
                { label: "整改内容", name: "ContentDetail", index: "Content", width: 150, align: "left" },
                {
                    label: "整改期限", name: "DateLimit", index: "DateLimit", width: 80, align: "left", formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd hh:mm:ss');
                    }
                },
                {
                    label: "是否需要复验", name: "CheckMark", index: "CheckMark", width: 100, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == 1)
                            //return "<i class='fa fa-check fa-2x' style='color:green;margin-left:10px;'><i/>";
                            return "需要";
                        else return "不需要";
                    }
                },
                {
                    label: "开单人", name: "CreateUserName", index: "CreateUserName", width: 80, align: "left"
                },
                 {
                     label: "开单日期", name: "CreateDate", index: "CreateDate", width: 80, align: "left", formatter: function (cellvalue, options, rowObject) {
                         return formatDate(cellvalue, 'yyyy-MM-dd hh:mm:ss');
                     }
                 },
                {
                    label: "单据状态", name: "State", index: "State", width: 100, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == 1 || cellvalue == 3) return "<i class='fa' style='color:green;margin-left:10px;'>已完成<i/>";
                        else if (cellvalue == 0) return "<i class='fa' style='color:red;margin-left:10px;'>未完成<i/>";
                        else if (cellvalue == 2) return "<i class='fa' style='color:red;margin-left:10px;'>复验未通过待重做<i/>";
                        else if (cellvalue == 4) return "<i class='fa' style='color:red;margin-left:10px;'>已取消<i/>";
                        else return "";
                    }
                },
                { label: "单据状态说明", name: "StateMemo", index: "StateMemo", width: 100, align: "left" },
                {
                    label: "完成时间", name: "StateDate", index: "StateDate", width: 100, align: "left", formatter: function (cellvalue, options, rowObject) {
                        if (rowObject.State == 1)
                            return formatDate(cellvalue, 'yyyy-MM-dd hh:mm:ss');
                        else
                            return "";
                    }
                },
               {
                   label: "复验结果", name: "CheckFlag", index: "CheckFlag", width: 100, align: "left",
                   formatter: function (cellvalue, options, rowObject) {
                       if (cellvalue == 1) return "<i class='fa' style='color:green;'>通过<i/>";
                       else if (cellvalue == 0) return "<i class='fa' style='color:red;'>不通过<i/>";
                       else if (rowObject.CheckMark == 1) return "<i class='fa' style='color:red;'>待复验<i/>";
                       else return "";
                   }
               },
                { label: "复验人", name: "CheckUerName", index: "CheckUerName", width: 100, align: "left" },
                {
                    label: "复验时间", name: "CheckDate", index: "CheckDate", width: 100, align: "left", formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd hh:mm:ss');
                    }
                }


            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'Date',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //点击时间范围（今天、近7天、近一个月、近三个月）
        $("#time_horizon a.btn-default").click(function () {
            $("#time_horizon a.btn-default").removeClass("active");
            $(this).addClass("active");
            switch ($(this).attr('data-value')) {
                case "1"://今天
                    $("#StartTime").val("@DateTime.Now.ToString("yyyy-MM-dd")");
                    $("#EndTime").val("@DateTime.Now.ToString("yyyy-MM-dd")");
                    break;
                case "2"://近7天
                    $("#StartTime").val("@DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd")");
                    $("#EndTime").val("@DateTime.Now.ToString("yyyy-MM-dd")");
                    break;
                case "3"://近一个月
                    $("#StartTime").val("@DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd")");
                    $("#EndTime").val("@DateTime.Now.ToString("yyyy-MM-dd")");
                    break;
                case "4"://近三个月
                    $("#StartTime").val("@DateTime.Now.AddMonths(-3).ToString("yyyy-MM-dd")");
                    $("#EndTime").val("@DateTime.Now.ToString("yyyy-MM-dd")");
                    break;
                default:
                    break;
            }
            $("#SelectedStartTime").html($("#StartTime").val());
            $("#SelectedEndTime").html($("#EndTime").val());
            $('#btn_Search').trigger("click");
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        $("#State .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#State .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = $("#queryCondition").GetWebControls();
            queryJson["Organizeid"] = _organizeid;
            queryJson["PStructId"] = _PStructId;
            queryJson["SourceType"] = _SourceType;
            queryJson["State"] = $("#State .dropdown-text").attr('data-value');
            $gridTable.jqGrid('setGridParam', {
                url: "../../PropertyManage/CS_Rectification/GetPageListJson",
                postData: { queryJson: JSON.stringify(queryJson) },
                page: 1
            }).trigger('reloadGrid');
        });
        //查询事件
        $("#btn_Reset").click(function () {
            $("#Name").val("");
            $("#Code").val("");
        });
        //查询回车
        $('#keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    ////新增
    //function btn_add() {
    //    dialogOpen({
    //        id: "Form",
    //        title: '添加整改单',
    //        url: '/PropertyManage/CS_Rectification/Form',
    //        width: "1000px",
    //        height: "550px",
    //        btn: ['保存', '审核', '关闭'],
    //        callBack: function (iframeId) {
    //            top.frames[iframeId].AcceptClick();
    //        }
    //    });
    //};
    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        var SourceId = $("#gridTable").jqGridRowValue("SourceId");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '编辑整改单',
                url: '/PropertyManage/CS_Rectification/Form?keyValue=' + keyValue + "&SourceId=" + SourceId,
                width: "1000px",
                height: "550px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }
    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: "../../PropertyManage/CS_Rectification/RemoveForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的单据！', 0);
        }
    }

</script>

<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel" style="height:35%;">
            <div class="panel-Title">整改单种类</div>
            <div id="itemTree1"></div>
        </div>
        <div class="west-Panel" style="height:62.5%;overflow-y:auto;">
            <div class="panel-Title" style="height:28px;padding-left:0px;"><div id="PStructTree" type="selectTree" class="ui-select"></div></div>
            <div id="itemTree2"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="panel-Title">整改单信息</div>
            <div class="titlePanel">
                <div class="title-search">
                    <table id="queryCondition">
                        <tr>
                            <td style="padding-left: 10px;">
                                <div class="ui-filter" style="width: 200px;">
                                    <div class="ui-filter-text">
                                        <strong id="SelectedStartTime">@DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd")</strong> 至 <strong id="SelectedEndTime">@DateTime.Now.ToString("yyyy-MM-dd")</strong>
                                    </div>
                                    <div class="ui-filter-list" style="width: 350px;">
                                        <table class="form" id="filter-form">
                                            <tr>
                                                <th class="formTitle">开单日期：</th>
                                                <td class="formValue">
                                                    <div style="float: left; width: 45%;">
                                                        <input id="StartTime" readonly type="text" value="@LeSoft.Util.Time.GetDate(-7)" class="form-control input-wdatepicker" onfocus="WdatePicker({maxDate:'%y-%M-%d'})">
                                                    </div>
                                                    <div style="float: left; width: 10%; text-align: center;">至</div>
                                                    <div style="float: left; width: 45%;">
                                                        <input id="EndTime" readonly type="text" value="@LeSoft.Util.Time.GetToday()" class="form-control input-wdatepicker" onfocus="WdatePicker({maxDate:'%y-%M-%d'})">
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">完成状态：</td>
                                                <td class="formValue">
                                                    <div class="btn-group" id="State">
                                                        <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择完成状态</a>
                                                        <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                                        <ul class="dropdown-menu" id="condition">
                                                            <li><a data-value="">所有</a></li>
                                                            <li><a data-value="0">未完成</a></li>
                                                            <li><a data-value="1">完成</a></li>
                                                        </ul>
                                                    </div>
                                                </td>
                                            </tr>
                                            @*<tr>
                                                    <td class="formTitle">商户名称</td>
                                                    <td class="formValue">
                                                        <input id="Name" type="text" class="form-control">
                                                    </td>
                                                </tr>*@
                                            <tr>
                                                <td class="formTitle">单据编号：</td>
                                                <td class="formValue">
                                                    <input id="Code" type="text" class="form-control">
                                                </td>
                                            </tr>
                                        </table>
                                        <div class="ui-filter-list-bottom">
                                            <a id="btn_Reset" class="btn btn-default">&nbsp;重&nbsp;&nbsp;置</a>
                                            <a id="btn_Search" class="btn btn-primary">&nbsp;查&nbsp;&nbsp;询</a>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td style="padding-left: 10px;">
                                <div id="time_horizon" class="btn-group">
                                    <a class="btn btn-default" data-value="1">今天</a>
                                    <a class="btn btn-default active" data-value="2">近7天</a>
                                    <a class="btn btn-default" data-value="3">近1个月</a>
                                    <a class="btn btn-default" data-value="4">近3个月</a>
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        @*<a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>*@
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>
                    @*<script>$('.toolbar').authorizeButton()</script>*@
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>